<?php
namespace data\admin;
use \data\BaseData;
/**
 * 管理员数据管理
 */
class AdminData extends BaseData{
    
    /**
     * 读取一个管理员信息
     */
    public function find($param){
        $fields = ['memberid','account','mobile','usercode','email'];
        $where = $this->parseWhere($fields,$param);
        if( !$where )  dataE('查询条件不能为空');
        $info  = M('member')->where($where)->find();
        return $info;
    }
    
    /**
     * 添加一个管理员信息
     */
    public function add($data){        
        $check = [                    
            'usercode'  => ['check'=>'must','msg'=>'会员编码不能为空'],
            'account'   => ['check'=>'must','msg'=>'账号不能为空','reg'=>'account'],
            'password'  => ['check'=>'must','msg'=>'密码不能为空'],            
            'passsalt'  => ['check'=>'must'],
            'truename'  => '',
            'mobile'    => ['reg'=>'mobile'],
            'gender'    => ['def'=>3,'reg'=>[1,2,3]],
            'birthday'  => ['reg'=>'int'],
            'email'     => ['reg'=>'email'],
            'addtime'   => ['val'=> SYS_TIME],
            'status'    => ['def'=>1],
        ];        
        $save = $this->verifyData($check,$data);
        return M('member')->insertGetId($save);
    }
    
    /**
     * 修改一个管理员信息
     */
    public function edit($memberid, $data){
        $check = [                    
            //'usercode'  => ['check'=>'must','msg'=>'会员编码不能为空'],
            'account'   => ['reg'=>'account'],
            'password'  => '',   
            'passsalt'  => '',
            'truename'  => '',
            'mobile'    => ['reg'=>'mobile'],
            'gender'    => ['reg'=>[1,2,3]],
            'birthday'  => ['reg'=>'int'],
            'email'     => ['reg'=>'email'],            
            'status'    => ['reg'=>[1,2]],
            'edittime'  => ['val'=> SYS_TIME],
        ];        
        $save = $this->verifyData($check,$data);
        if( !$save ) return false;
        $where = ['memberid'=>$memberid];
        $result = M('member')->where($where)->update($save);
        if($result === false ) dataE('修改账户信息失败');
        return $result;
    }
    
}